Deploying Kanzi applications to Android

Before you can build and deploy Kanzi applications to Android devices, you need to set up the Kanzi build environment for Android and install on your computer the USB device drivers for your Android device. See Installing the Kanzi build environment for Android.

Building and deploying Kanzi applications to Android from Kanzi Studio

If your Kanzi application includes a Kanzi Engine plugin, you have to build and deploy your application manually. See Building and deploying Kanzi applications to Android manually.

To build and deploy your Kanzi application to Android from Kanzi Studio:

  1. If you add content to your application using the Kanzi Engine API, make sure to include that content in the <ProjectName>/configs/android/build.xml file in the <target name="-pre-compile"> target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use
    <target name="-pre-compile">
            <echo>Copying assets</echo>
            <copy todir="${asset.absolute.dir}">
                <fileset dir="${asset.absolute.dir}/../../../../bin">
                    <include name="**/*.kzb"/>
                    <include name="**/*.cfg"/>
                    <include name="**/*.xml"/>
                    <include name="**/*.png"/>
  2. Connect your Android device to your computer.
  3. In Kanzi Studio create or open the project for your Kanzi application and select File > Export > Build Android Package.
    Kanzi Studio builds the application source code, creates .apk package, and installs the package to your Android device.

Configuring Android builds

You can configure the building of your Kanzi applications for Android using the application configurations in Kanzi Studio. For example, you can set the target architecture, and whether Kanzi should deploy the built package to the attached target device. You can set which application configuration you want to use when you select File > Export > Build Android Package in Project > Properties in the Default Build Configuration property.

  1. In Kanzi Studio in the Library right-click Applications and select Create Application Configuration.
  2. In the Properties set the configuration for the Android build.
    For example:

Setting the Java version for Kanzi applications

To set the Java version for your Kanzi applications for Android, add to the Application/configs/platforms/android/build.xml as the first child elements of the top level <project> element and set the value attribute to the Java version you want to use

<property name="java.target" value="7" />
<property name="java.source" value="7" />

Building and deploying Kanzi applications to Android manually

SCons runs the SConstruct file in the configuration directory of the platform from which you run the scons command. SConstruct file is the entry point for building the application and contains the information about the Kanzi Engine location and runs these files:

To build and deploy Kanzi applications to Android manually:

  1. If you add content to your application using the Kanzi Engine API, make sure to include that content in the <ProjectName>/configs/android/build.xml file in the <target name="-pre-compile"> target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use
    <target name="-pre-compile">
            <echo>Copying assets</echo>
            <copy todir="${asset.absolute.dir}">
                <fileset dir="${asset.absolute.dir}/../../../../bin">
                    <include name="**/*.kzb"/>
                    <include name="**/*.cfg"/>
                    <include name="**/*.xml"/>
                    <include name="**/*.png"/>
  2. Connect your Android device to your computer.
  3. Open the command line in the configuration directory of the platform for which you want to build the Kanzi application (<ProjectName>/Application/configs/platforms/<PlatformName>) and make sure you have the correct environmental variables set. See Setting the Kanzi environment variables.
    For example, to build your Kanzi application for:
  4. Run the scons command with the build parameters for your Kanzi application.

    Syntaxscons <library> <type> <name>
    Parameters
    library

    (Optional) the graphics library:

    • ES2 builds the application with OpenGL ES 2.0
    • GL builds the application with OpenGL
    type

    (Optional) the build type:

    • Release builds the application with compiler optimizations enabled. The release option builds smaller files than the debug option. Use this option for production purposes. Default value.
    • Debug builds the application with disabled compiler optimizations and contains full debug information you can use with a debugger. The debug option builds larger files and debug applications run slower. Use this option for development purposes.
    • Profile builds the application with compiler optimizations enabled, but without stripping the debug information that enables you to track the performance in some parts of the Kanzi Engine. Use this option when you want to measure the performance of your application. For example, when you want to find out which parts of the application take a lot of time to run, or which parts are called a large number of times.
    name(Optional) the name of the project
    Examples

    // Builds the application with the default settings as specified
    // in config.py and SConstruct configuration files.
    scons
    // Builds the debug version of the application with
    // the OpenGL graphics library.
    scons GL debug
    // Builds the debug version of the application with the
    // OpenGL ES 2.0 graphics library from the Kanzi Studio
    // project named MyProject.
    scons ES2 debug MyProject

    Scons builds the Kanzi application source code and binary files in the <ProjectName>/Application/output directory.

  5. In the <ProjectName>/Application/output directory run adb install or ant release install to install the .apk package of your Kanzi application on your Android device.
    For example, if your project is called MyProject and is stored in the <KanziWorkspace> run:
    adb install MyProject.apk

    or
    ant release install

Troubleshooting

See also

Installing the Kanzi build environment for Android

Installing the Kanzi build environment manually

Tutorial: Create a simple in-vehicle infotainment application

Android OEM USB Drivers

Deploying Kanzi applications